<@admin.header title="选择用户">
</@admin.header>
    <body>
        <div class="rightinfo">
        	<div class="formbody">
		        <div class="formtitle">
		            <span>选择用户</span>
		        </div>
				<ul class="forminfo">
		            <li>
		            	<input type="hidden" id="startId" value="0" />
		                <label class="field" style="width:140px;">名称/电话号码/邮箱地址</label>
		                <input id="keyword" type="text" class="dfinput" onkeyup="javascript:if(event.keyCode==13) search();"/>
						<button class="btn" onclick="search();">搜索</button>
		            </li>
				</ul>
			</div>
        	<!--默认查询表单-->
            <table class="tablelist">
                <thead>
                    <tr>
                    	<th width="80"><input onchange="toggle(this);" type="checkbox"/></th>
						<th width="160">用户名</th>
	                    <th width="160">邮箱</th>
	                    <th width="160">手机</th>
	                    <th width="160">注册时间</th>
	                    <th width="100">是否为管理员</th>
                    </tr>
                </thead>
				<tbody id="contact_body" style="max-height:500px;overflow-y:auto;">
                </tbody>
            </table>
			
			<div>
				<a style="float:right;" class="ibtn" href="javascript:loadMore();">加载更多</a>
			</div>
			<div class="clear"></div>
			<div class="xline"></div>
			<div style="text-align:center;margin-top:10px;">
				<button class="btn" onclick="ok();">选择完成</button>
				<button class="btn" onclick="cancel();">关闭窗口</button>
			</div>
        </div>
    </body>
	<script>
	var keyword = "";
	var form = new App.common.form();
	var ajax = new App.common.ajax();
	var dialog = new App.common.dialog();
	var selecIds = "${ids!''}";
	
	function toggle(o){form.checkToggle('contact',o);}
	$(document).ready(function(){
		loadMore();
	});
	function search(){
		keyword =$("#keyword").val();
		$("#startId").val('0');
		$("#contact_body").html("");
		loadMore();
	}
	
	function loadMore(){
		var startId = $("#startId").val();
		ajax.post("auth/user/select.do",{"totalCount":startId,"keyword":keyword},null,function(d){
			if(App.isEmpty(d)){
				dialog.alert("没有更多了");				
			}else{
				$('#contact_body').append(d);
				$("#startId").val($("#contact_body tr:last").attr("cid"));
				
				configSelect();
			}
		});
	}
	
	function configSelect(){
		$("input[pass='0']").each(function(){
			if(selecIds.indexOf($(this).val()+";")>-1)
				this.checked=true;
			$(this).attr("pass",1);
		});
	}
	
	function cancel(){
		dialog.confirm("确定关闭窗口吗？",function(){
			window.close();
		});
	}
	
	function ok(){
		var ids='', names='';
		$("input[name=contact]").each(function() {
			if(this.checked){
				ids+=$(this).val()+";";
				names+=$(this).attr("uname")+";";
			}
		});
		if(App.isEmpty(ids)){
			dialog.alert("没有选中的值，请先选择");return false;
		}
		opener.${func!'contactBack'}($.trim(ids),$.trim(names));
		window.close();
	}
	</script>
</html>